package com.study.redis.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedisPool;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by he on 2018/6/4.
 */
@Configuration
public class RedisConfiguration {
    @Autowired
    private RedisConfig redisConfig;

    @Bean
    public ShardedJedisPool convertJedisPool(){
        JedisPoolConfig jedisPool = new JedisPoolConfig();
        List<JedisShardInfo> list = new ArrayList<>();
        JedisShardInfo info = new JedisShardInfo(redisConfig.getHost(), redisConfig.getPort());
        info.setPassword(redisConfig.getPassword());
        list.add(info);
        return new ShardedJedisPool(jedisPool, list);
    }
}
